<?xml version="1.0" encoding="UTF-8" ?>
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
    xmlns:calli="http://callimachusproject.org/rdf/2009/framework#"
    xmlns:foaf="http://xmlns.com/foaf/0.1/"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
    xmlns:dc="http://purl.org/dc/elements/1.1/">
<head>
    <title resource="?this">{rdfs:label}</title>
    <link rel="help" href="../../callimachus-for-web-developers#Home_Folder_Edit_Tab" target="_blank" title="Help" />
    <link id="layout-sample" href="../../default-layout.xq" />
    <link id="auth-folder" href="/auth/" />
    <link id="credentials-folder" href="/auth/credentials/" />
    <script type="text/javascript">
    // <![CDATA[
    jQuery(function($){
        $('#pattern').change(function(){
             $('span.pattern').attr('content', this.value);
        });
        $('#type').change(function(){
            if (this.value) {
                $('span.pattern').remove();
                $('#pattern').parent().append('<span class="pattern" />');
                $('span.pattern').attr('property', this.value);
                $('#pattern').change();
            }
        });
        $('span.pattern[property]').each(function(){
            if (this.getAttribute('content')) {
                $('#pattern').val(this.getAttribute('content'));
                $('#type').val(this.getAttribute('property'));
            }
        });
        $('#type').change();
        window.deleteFolder = function(event) {
            if (!confirm("Are you sure you want to delete this folder and all the contents of this folder?"))
                return false;
            var xhr = $.ajax({
                type: 'DELETE',
                url: '?archive',
        		dataType: "text",
        		xhrFields: calli.withCredentials,
                beforeSend: function(xhr){
                    var etag = calli.etag('?archive');
                    if (etag) {
                        xhr.setRequestHeader("If-Match", etag);
                    }
                },
                success: function(data, textStatus) {
                    event.message = '';
                    calli.deleteResource(event);
                }
            });
        };
        $('#layout').bind('calliLinked', function(event) {
            $(this).children(':not(:last-child)').remove();
        });
    });
    // ]]>
    </script>
</head>
<body resource="?this">
    <h1 property="rdfs:label" />
    <div id="sidebar">
        <aside>
            <p>Layout is the extra markup that is applied to every xhtml template within this realm</p>
            <p>Allow origins are the origins of scripts that can make requests to resources within this realm</p>
            <p>Credentials are the username and passwords that should be used for outgoing requests from scripts within this realm</p>
        </aside>
        <aside>
            <p>Directory index determines how requests directly to this folder should be handled</p>
            <p>The type is the response code that is sent</p>
            <p>Content location is what should be returned to the browser</p>
            <p>Cache control explains how frequently this is expected to change</p>
        </aside>
    </div>
    <form role="form" id='form' method="POST" action="" enctype="application/sparql-update" resource="?this">
        <div class="hbox">
            <fieldset>
                <legend>Realm settings</legend>
                <div dropzone="link s:text/uri-list" class="form-group"
                        ondrop="return calli.insertResource(event)">
                  <label>Layout <a href="../types/XQuery?create" title="Customize"
                      onclick="return calli.createResource(event, this.href + '#!' + $('#layout-sample').attr('href'))" class="glyphicon glyphicon-list-alt" /></label>
                  <div id="layout" rel="calli:layout" class="controls vbox">
                    <span resource="?layout" class="ui-state-highlight ui-corner-all">
                      <span property="rdfs:label" />
                    </span>
                  </div>
                </div>
                <div class="form-group">
                    <label for="allowOrigin">Allowed origins</label>
                    <div class="controls">
                        <div property="calli:allowOrigin" content="?allowOrigin">
                            <input type="text" class="form-control" value="{?allowOrigin}" />
                        </div>
                        <a href="javascript:void(0)" title="More" onclick="return calli.addResource(event)" class="glyphicon glyphicon-plus" />
                    </div>
                </div>
                <div dropzone="link s:text/uri-list" class="form-group"
                        ondrop="return calli.insertResource(event)">
                  <label>Authentication <a href="../types/AuthManager" title="Create authentication manager"
                      onclick="return calli.createResource(event, $('#auth-folder').attr('href') + '?create=' + encodeURIComponent(this.href) + '#' + $('#form').attr('resource'))" class="glyphicon glyphicon-list-alt" /></label>
                  <div id="authentication" rel="calli:authentication" class="controls vbox">
                    <span resource="?authentication" typeof="calli:AuthenticationManager" class="ui-state-highlight ui-corner-all">
                        <span property="rdfs:label" />
                        <a href="{?authentication}" title="Don't use this authentication here" onclick="return calli.removeResource(event)" class="glyphicon glyphicon-remove" />
                    </span>
                  </div>
                </div>
                <div dropzone="link s:text/uri-list" class="form-group"
                        ondrop="return calli.insertResource(event)">
                  <label>Credentials <a href="../types/Credential" title="Create credential"
                      onclick="return calli.createResource(event, $('#credentials-folder').attr('href') + '?create=' + encodeURIComponent(this.href))" class="glyphicon glyphicon-list-alt" /></label>
                  <div id="credentials" rel="calli:credentials" class="controls vbox">
                    <span resource="?credential" typeof="calli:Credential" class="ui-state-highlight ui-corner-all">
                        <span property="rdfs:label" />
                        <a href="{?credential}" title="Don't use this credential here" onclick="return calli.removeResource(event)" class="glyphicon glyphicon-remove" />
                    </span>
                  </div>
                </div>
            </fieldset>
            <fieldset>
                <legend>Directory index</legend>
                <div class="form-group">
                    <label for="type">Type</label>
                    <div class="controls">
                        <select id="type">
                            <option value="calli:copy">Copy (200)</option>
                            <option value="calli:canonical">Canonical (301)</option>
                            <option value="calli:alternate">Alternate (302)</option>
                            <option value="calli:describedby" selected="selected">Described by (303)</option>
                            <option value="calli:resides">Resides (307)</option>
                            <option value="calli:moved">Moved (308)</option>
                            <option value="calli:missing">Missing (404)</option>
                            <option value="calli:gone">Gone (410)</option>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label for="pattern">Content location</label>
                    <div class="controls">
                        <input type="text" class="form-control" id="pattern" size="40" value="" />
                        <span class="pattern" property="calli:copy" content="?copy" />
                        <span class="pattern" property="calli:canonical" content="?canonical" />
                        <span class="pattern" property="calli:alternate" content="?alternate" />
                        <span class="pattern" property="calli:describedby" content="?describedby" />
                        <span class="pattern" property="calli:resides" content="?resides" />
                        <span class="pattern" property="calli:moved" content="?moved" />
                        <span class="pattern" property="calli:missing" content="?missing" />
                        <span class="pattern" property="calli:gone" content="?gone" />
                    </div>
                </div>
                <div class="form-group">
                    <label for="cache">Cache control</label>
                    <div class="controls">
                		<input type="text" class="form-control"  id="cache" value="{calli:cacheControl}" placeholder="max-age=3600" />
                    </div>
                </div>
            </fieldset>
        </div>
        <fieldset class="form-group">
            <button id="save" type="submit" class="btn btn-primary">Save</button>
            <button id="cancel" type="button" onclick="window.location.replace('?view')" class="btn btn-default">Cancel</button>
            <button id="delete" type="button" onclick="deleteFolder(event)" class="btn btn-danger">Delete</button>
        </fieldset>
    </form>
</body>
</html>
